<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
  function getNowFormatTime() {
    var nowDate = new Date();
    var h = nowDate.getHours();
    var m = nowDate.getMinutes();
    var s = nowDate.getSeconds();
    //补全0，并拼接
    return getNowFormatDay(nowDate) + " " + completeDate(h) + ':' + completeDate(m) + ':' + completeDate(s);
  }
  //补全0
  function completeDate(value) {
    return value < 10 ? "0"+value:value;
  }
  //获取当前日期，格式YYYY-MM-DD
  function getNowFormatDay(nowDate) {
    var char = "-";
    if(nowDate == null){
        nowDate = new Date();
    }
    var day = nowDate.getDate();
    var month = nowDate.getMonth() + 1;//注意月份需要+1
    var year = nowDate.getFullYear();
    //补全0，并拼接
    return year + char + completeDate(month) + char +completeDate(day);
    // +" 00:00:00"
  }
  </script>
</body>
</html>